package com.macrog.test;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.*;

/**
 * Created by guohong on 2018/7/12.
 */
public class MsgProvider {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext application=new ClassPathXmlApplicationContext("classpath:spring/spring-rabbitmq.xml");
        AmqpTemplate amqpTemplate=(AmqpTemplate) application.getBean("amqpTemplate");

        List<Map<String, Object>> list=new ArrayList<Map<String, Object>>();
        Map<String, Object> map=new HashMap<String, Object>();
        map.put("name", "zhangsan");
        map.put("age", 20);
        map.put("time", new Date());
        list.add(map);

        //第一个参数为routingKey,第二个参数为发送的数据，方法把java对象转成json字符串，再转成字节数组，封装成message发送
        amqpTemplate.convertAndSend("spring_queue_test_01_key", list);

        application.close();

        System.out.println("msg send ok");
    }

}
